<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">

<script type="text/javascript">
function initLogs()
{
	jgrouse.log.addHandler(new jgrouse.logHandlers.ConsoleLog());
}

jgrouse_config = 
{
	initLogs : initLogs,
	logLevel : 'INFO',
	nologs : false,
	debug : true
}
</script>

<script type="text/javascript" src='../src/jgrouse.js'></script>
<script type="text/javascript" src='../src/log.js'></script>
<script type="text/javascript" src='../src/classloader.js'></script>
<script type="text/javascript" src='../src/jsunit.js'></script>


<script type="text/javascript">


jgrouse.module(
{
	name:'testPCS', 
	requires:['jgrouse.util.PropertyChangeSupport'], 
	imports : ['jgrouse.util.PropertyChangeSupport'],  
	body:function(salt)
	{
		eval(salt);
	
		testPCS = {};
	
	
		jgrouse.define('testPCS.SampleListener', 'jgrouse.BaseObject', function(salt)
		{
			eval(salt);
			
			
			return {
				initialize : function()
				{
					_super(this, 'initialize');
					this._triggered = {};
				},
				
				onPropertyChanged : function(event)
				{
					var c = this._triggered[event.getPropertyName()];
					this._triggered[event.getPropertyName()] = (c == undefined)? 1 : c + 1;
				},
				
				onTestPropertyChanged : function(newValue, oldValue)
				{
					this._testProperty = newValue;
				},
				
				onTriggerTest : function(newValue, oldValue)
				{
					this._triggerTest = newValue;
				}
			}
		});
	},
	postInit : function(embed)
	{
		eval(embed);
		eval(jgrouse.getImportString('jgrouse.jsunit.*'));
		testPCS.run = function()
		{
			var pcs = new PropertyChangeSupport();
			var sample = new testPCS.SampleListener();
			pcs.addListener('testProperty', sample);
			pcs.addListener('triggerTest', sample);
			pcs.addListener('namedProp', sample);
			pcs.addListener(sample);
			
			pcs.firePropertyChange('testProperty', 'one', 'zero');
			pcs.firePropertyChange('triggerTest', 'two', 'three');
			pcs.firePropertyChange('namedProp', 'namedPropValue');
			pcs.firePropertyChange('anonProp', 'anonPropValue');
			
			assertEqual(sample._testProperty, 'one');
			assertEqual(sample._triggerTest, 'two');
			assertEqual(sample._triggered['namedProp'], 2);
			assertEqual(sample._triggered['anonProp'], 1);
			
			pcs.removeListener(sample);
			pcs.firePropertyChange('anonProp', 'anonPropValue');
			assertEqual(sample._triggered['anonProp'], 1);
			pcs.removeListener('namedProp', sample);
			pcs.firePropertyChange('namedProp', 'namedPropValue');
			assertEqual(sample._triggered['namedProp'], 2);
			pcs.removeListener('triggerTest', sample);
			pcs.firePropertyChange('triggerTest', 'four', 'two');
			assertEqual(sample._triggerTest, 'two');
			pcs.removeListener('testProperty', sample);
			pcs.firePropertyChange('testProperty', '99', '32');
			assertEqual(sample._testProperty, 'one');
			
			
		}
	}
});



</script>
</head>

<body>
	This is a collection of unit tests for PropertyChangeSupport component.
	Any errors would be logged below.
</body>
<script type="text/javascript">
		jgrouse.require('testPCS', function()
		{
			testPCS.run();
		});
</script>
</html>